{% load static %}
<!doctype html>
<html class="no-js" lang="zxx">
<head>
    <meta charset="utf-8">
    <title>基金信息</title>
    <link rel="shortcut icon" type="image/x-icon" href="{% static 'images/icon/favicon.png' %}">

    <!-- CSS here -->
    <link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}">
    <link rel="stylesheet" href="{% static 'css/style.css' %}">
    <script src="{% static 'js/echarts.min.js' %}"></script>
</head>
<body>
    <header>
        <div class="header-area header-transparent">
            <div class="main-header header-sticky">
                <div class="container-fluid">
                    <div class="menu-wrapper d-flex align-items-center justify-content-between">
                        <div class="left-content d-flex align-items-center">
                            <div class="logo">
                                <a href="{% url 'index' %}"><img src="{% static 'images/logo/logo-test.png' %}" alt=""></a>
                            </div>
                            <!-- Main-menu -->
                            <div class="main-menu d-none d-lg-block">
                                <nav>
                                    <ul id="navigation">
                                        <li><a href="{% url 'index' %}">主页</a></li>
                                        <li><a>列表<i class="fas fa-angle-down"></i></a>
                                            <ul class="submenu">
                                                <li><a href="{% url 'funds' %}">基金列表</a></li>
                                                <li><a href="{% url 'users' %}">用户列表</a></li>
                                            </ul>
                                        </li>
                                        <li><a href="{% url 'chart' %}">统计图表</a></li>
                                    </ul>
                                </nav>
                            </div>
                        </div>
                        <!-- Button -->
                        <div class="buttons">
                            <ul>
                                <li class="button-header">
                                    <form action="{% url 'logout' %}">
                                        <input type="submit" value="退出登录" class="btn header-btn2">
                                    </form>
                                </li>
                            </ul>
                        </div>
                    </div>
                    <!-- Mobile Menu -->
                    <div class="col-12">
                        <div class="mobile_menu d-block d-lg-none"></div>
                    </div>
                </div>
            </div>
        </div>
    </header>
    <main>
        <!-- Hero Area Start-->
        <div class="slider-area hero-bg1">
            <div class="single-slider hero-overly slider-height3 d-flex align-items-end">
                <div class="container">
                    <div class="directory-details-head pb-40">
                        <div class="wants-wrapper w-padding3">
                            <div class="row align-items-center justify-content-between">
                                <div class="col-xxl-8 col-xl-6 col-lg-6">
                                    <div class="details-cap d-flex">
                                        <div class="properties__caption">
                                            <h3 style="font-size: 50px">{{ fund.fund_name }}</h3>
                                            <p style="font-size: 25px">基金代码：{{ fund.fund_id }}</p>
                                            {% if fund.category == 2 %}
                                                <p style="font-size: 25px">基金类型：混合型</p>
                                            {% elif fund.category == 3 %}
                                                <p style="font-size: 25px">基金类型：债券型</p>
                                            {% elif fund.category == 5 %}
                                                <p style="font-size: 25px">基金类型：货币型</p>
                                            {% elif fund.category == 1 %}
                                                <p style="font-size: 25px">基金类型：股票型</p>
                                            {% else %}
                                                <p style="font-size: 25px">基金类型：指数型</p>
                                            {% endif %}
                                        </div>
                                    </div>
                                </div>
                                <div class="col-xxl-4 col-xl-6 col-lg-6">
                                    <div class="double-btn f-right  d-flex flex-wrap">
                                        <!--
                                        <form action="./delete">
                                            <input type="hidden" name="id" value="{{ fund.fund_id }}">
                                            <input type="submit" onclick="return deleteFund()" value="删除" class="border-btn w-btn wantToWork-btn">
                                        </form>
                                        -->
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--Hero Area End-->

        <div class="directory-details section-padding">
            <div class="container">
                <div class="row" style="float: left;width: 50%;">
                    <div class="col-lg-8">
                        <div class="small-tittle mb-20">
                            <h2 style="font-size: 45px">详细信息</h2>
                        </div>
                        <div class="directory-cap mb-40">
                            <table class="table">
                                <tbody>
                                    <tr>
                                        <td>
                                            <p>基金经理：{{ fund.manager }}</p>
                                        </td>
                                        <td>
                                            <form onsubmit="return check(1)" action="./modify">
                                                <input type="hidden" name="type" value="1">
                                                <input type="hidden" name="fundId" value="{{ fund.fund_id }}">
                                                <input type="text" style="width: 60px" id="newManager" name="manager">
                                                <input type="submit" value="修改" class="btn btn-success" style="height: 10px;padding: 15px 15px">
                                            </form>
                                        </td>
                                    </tr>

                                    <tr>
                                        <td>
                                            <p>起购额度：{{ fund.buy_min }}</p>
                                        </td>
                                        <td>
                                            <form onsubmit="return check(2)" action="./modify">
                                                <input type="hidden" name="type" value="2">
                                                <input type="hidden" name="fundId" value="{{ fund.fund_id }}">
                                                <input type="text" style="width: 60px" id="newBuyMin" name="buyMin" >
                                                <input type="submit" value="修改" class="btn btn-success" style="height: 10px;padding: 15px 15px">
                                            </form>
                                        </td>
                                    </tr>

                                    <tr>
                                        <td>
                                            <p>原始买入费率：{{ fund.buy_source_rate }}</p>
                                        </td>
                                        <td>
                                            <form onsubmit="return check(3)" action="./modify">
                                                <input type="hidden" name="type" value="3">
                                                <input type="hidden" name="fundId" value="{{ fund.fund_id }}">
                                                <input type="text" style="width: 60px" id="newBuySourceRate" name="buySourceRate">
                                                <input type="submit" value="修改" class="btn btn-success" style="height: 10px;padding: 15px 15px">
                                            </form>
                                        </td>
                                    </tr>

                                    <tr>
                                        <td>
                                            <p>当前买入费率：{{ fund.buy_rate }}</p>
                                        </td>
                                        <td>
                                            <form onsubmit="return check(4)" action="./modify">
                                                <input type="hidden" name="type" value="4">
                                                <input type="hidden" name="fundId" value="{{ fund.fund_id }}">
                                                <input type="text" style="width: 60px" id="newBuyRate" name="buyRate">
                                                <input type="submit" value="修改" class="btn btn-success" style="height: 10px;padding: 15px 15px">
                                            </form>
                                        </td>
                                    </tr>

                                    <tr>
                                        <td>
                                            <p>日单位净值增长率：{{ fund.day_growth }}</p>
                                        </td>
                                        <td>
                                            <form onsubmit="return check(5)" action="./modify">
                                                <input type="hidden" name="type" value="5">
                                                <input type="hidden" name="fundId" value="{{ fund.fund_id }}">
                                                <input type="text" style="width: 60px" id="newDayGrowth" name="dayGrowth">
                                                <input type="submit" value="修改" class="btn btn-success" style="height: 10px;padding: 15px 15px">
                                            </form>
                                        </td>
                                    </tr>

                                    <tr>
                                        <td>
                                            <p>周单位净值增长率：{{ fund.week_growth }}</p>
                                        </td>
                                        <td>
                                            <form onsubmit="return check(6)" action="./modify">
                                                <input type="hidden" name="type" value="6">
                                                <input type="hidden" name="fundId" value="{{ fund.fund_id }}">
                                                <input type="text" style="width: 60px" id="newWeekGrowth" name="weekGrowth">
                                                <input type="submit" value="修改" class="btn btn-success" style="height: 10px;padding: 15px 15px">
                                            </form>
                                        </td>
                                    </tr>

                                    <tr>
                                        <td>
                                            <p>月单位净值增长率：{{ fund.month_growth }}</p>
                                        </td>
                                        <td>
                                            <form onsubmit="return check(7)" action="./modify">
                                                <input type="hidden" name="type" value="7">
                                                <input type="hidden" name="fundId" value="{{ fund.fund_id }}">
                                                <input type="text" style="width: 60px" id="newMonthGrowth" name="monthGrowth">
                                                <input type="submit" value="修改" class="btn btn-success" style="height: 10px;padding: 15px 15px">
                                            </form>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>

                </div>
                <div id="test" style="float: left;width: 50%;height: 480px;border:#e9e7fa 6px solid;border-radius: 10px">

                </div>

            </div>
        </div>

    </main>

    <script>
        function deleteFund() {
            if (confirm("确定要删除吗?"))
		     {
		         return true;
		     } else {
		         return false;
             }
        }
        function check(flag) {
            if (flag == 1) {        // 基金经理
                var re=/[^\u4E00-\u9FA5]/;
                var manager = document.getElementById("newManager");
                if (manager.value == "") {
                    alert("请不要输入空信息");
                    return false;
                } else if (re.test(manager.value)) {
                    alert("请输入正确的姓名");
                    return false;
                } else {
                    return true;
                }
            } else if (flag == 2) { // 起购额度
                var buyMin = document.getElementById("newBuyMin").value;
                if (buyMin == "" || buyMin == null) {
                    alert("请不要输入空信息");
                    return false;
                } else if (!isNaN(buyMin)) {
                    if (Number(buyMin) < 0) {
                        alert("请输入大于零的数字");
                        return false;
                    } else {
                        return true;
                    }
                } else {
                    alert("请输入正确的数字");
                    return false;
                }
            } else if (flag == 3) {
                var number = document.getElementById("newBuySourceRate").value;
                if (number == "" || number == null) {
                    alert("请不要输入空信息");
                    return false;
                } else if (!isNaN(number)) {
                    if (Number(number) < 0 || Number(number) >= 100) {
                        alert("请输入符合要求的数字");
                        return false;
                    } else {
                        return true;
                    }
                } else {
                    alert("请输入正确的数字");
                    return false;
                }
            } else if (flag == 4) {
                var number = document.getElementById("newBuyRate").value;
                if (number == "" || number == null) {
                    alert("请不要输入空信息");
                    return false;
                } else if (!isNaN(number)) {
                    if (Number(number) < 0 || Number(number) >= 100) {
                        alert("请输入符合要求的数字");
                        return false;
                    } else {
                        return true;
                    }
                } else {
                    alert("请输入正确的数字");
                    return false;
                }
            } else if (flag == 5) {
                var number = document.getElementById("newDayGrowth").value;
                if (number == "" || number == null) {
                    alert("请不要输入空信息");
                    return false;
                } else if (!isNaN(number)) {
                    if (Number(number) < -100 || Number(number) >= 100) {
                        alert("请输入符合要求的数字");
                        return false;
                    } else {
                        return true;
                    }
                } else {
                    alert("请输入正确的数字");
                    return false;
                }
            } else if (flag == 6) {
                var number = document.getElementById("newWeekGrowth").value;
                if (number == "" || number == null) {
                    alert("请不要输入空信息");
                    return false;
                } else if (!isNaN(number)) {
                    if (Number(number) < -100 || Number(number) >= 100) {
                        alert("请输入符合要求的数字");
                        return false;
                    } else {
                        return true;
                    }
                } else {
                    alert("请输入正确的数字");
                    return false;
                }
            } else if (flag == 7) {
                var number = document.getElementById("newMonthGrowth").value;
                if (number == "" || number == null) {
                    alert("请不要输入空信息");
                    return false;
                } else if (!isNaN(number)) {
                    if (Number(number) < -100 || Number(number) >= 100) {
                        alert("请输入符合要求的数字");
                        return false;
                    } else {
                        return true;
                    }
                } else {
                    alert("请输入正确的数字");
                    return false;
                }
            }
        }
    </script>

<script type="text/javascript">
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('test'));

        // 指定图表的配置项和数据
        var option = {
            title: {
                text: '单位净值'
            },
            legend: {
                data:['销量']
            },
            tooltip: {},
            xAxis: {
                data: {{ date | safe}}
            },
            yAxis: {
                scale: true
            },
            series: [{
                name: '单位净值变化',
                type: 'line',
                data: {{ price }}
            }],
            backgroundColor: '#f0f0f4'
        };

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    </script>

</body>
</html>